package acm.集美大学;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class G猜单词 {
    static Handle[] handles = new Handle[5];
    static char[] chars = new char[3];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < handles.length; i++) {
            handles[i] = new Handle(sc.next().toCharArray(), sc.nextInt(), sc.nextInt());
        }
        List<String> list = new ArrayList<>();
        for (char i = 'A'; i <= 'Z'; i++) {
            chars[0] = i;
            for (char j = 'A'; j <= 'Z'; j++) {
                chars[1] = j;
                for (char k = 'A'; k <= 'Z'; k++) {
                    chars[2] = k;
                    boolean flag = true;
                    for (Handle handle : handles) {
                        if (!handle.match(chars)) {
                            flag = false;
                            break;
                        }
                    }
                    if (flag) list.add(new String(chars));
                }
            }
        }
        System.out.println(list.size());
        list.forEach(System.out::println);
    }

    static class Handle {
        char[] str;
        int[] count = new int[128];
        int a, b;

        public Handle(char[] str, int a, int b) {
            this.str = str;
            for (char c : str) {
                count[c]++;
            }
            this.a = a;
            this.b = b;
        }

        public boolean match(char[] chars) {
            int cnt = 0;
            for (char c : chars) {
                if (count[c] != 0) {
                    cnt++;
                }
            }
            if (this.a != cnt) return false;
            int b = 0;
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == str[i]) {
                    b++;
                }
            }
            return this.b == b;
        }
    }
}
